package com.dongjiantong.quarantine.serviceImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongjiantong.mybatis.ServiceMybatis;
import com.dongjiantong.quarantine.mapper.SupervisionRecordsSubMapper;
import com.dongjiantong.quarantine.model.SupervisionRecordsSub;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by mz on 26/12/17.
 *
 */
@Slf4j
@Service(version = "1.0.0")
public class SupervisionRecordsSubReadServiceImpl extends ServiceMybatis<SupervisionRecordsSub> implements SupervisionRecordsSubReadService{

    @Resource
    private SupervisionRecordsSubMapper supervisionRecordsSubMapper;


    /**
     * 查询督查的子标详情
     *
     * @param supervisionId 督查的主表id
     * @return List<Map<String , Object>>
     */
    @Override
    public List<Map<String , Object>> findBySupervisionId(Long supervisionId) {
        List<SupervisionRecordsSub> supervisionRecordsSubs = supervisionRecordsSubMapper.findBySupervisionId(supervisionId);
        List<Map<String , Object>> mapList = buildMapList(supervisionRecordsSubs);
        return mapList;
    }

    private List<Map<String,Object>> buildMapList(List<SupervisionRecordsSub> supervisionRecordsSubs) {
        List<Map<String , Object>> mapList = null;
        if(supervisionRecordsSubs != null && !supervisionRecordsSubs.isEmpty()){
            mapList = new ArrayList<>();
            for(SupervisionRecordsSub supervisionRecordsSub : supervisionRecordsSubs){
                Map<String , Object> map = Maps.newHashMap();
                map.put("id",supervisionRecordsSub.getId());
                map.put("supervision_id",supervisionRecordsSub.getSupervision_id());
                map.put("code",supervisionRecordsSub.getCode());
                map.put("name",supervisionRecordsSub.getName());
                map.put("type",supervisionRecordsSub.getType());
                map.put("is_ok",supervisionRecordsSub.getIs_ok());
                map.put("content",supervisionRecordsSub.getContent());
                mapList.add(map);
            }
        }

        return mapList;
    }
}
